1. /* scfcabsH.cpp by K.Tsuru */
  2. // function ID = 9001
  3. /***************************************
  4. SN library
  5. SComplex class reference
  6. It returns the absolute value of z in high precision version.
  7. ****************************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. SDouble CabsH(const SComplex& z){
  12. // z = x + iy
  13. SDouble x( z.Real() ), y( z.Imag() ), r;
  14. // It takes absolute values.
  15. if(x.Sign()<0) x.ChangeSign();
  16. if(y.Sign()<0) y.ChangeSign();
  17. // z = x+i*y
  18. if(x.Sign() == 0) return y; // |y|
  19. if(y.Sign() == 0) return x; // |x|
  20. // |z| = sqrt(x*x+y*y) = |x|*sqrt(1+(y/x)^2) for |x| > |y|
  21. if(x > y){ // |x|>|y|
  22. r = y/x;
  23. r = 1.0 + r*r;
  24. r = x*Sqrt(r);
  25. } else { // |x|<=|y|
  26. r = x/y;
  27. r = 1.0 + r*r;
  28. r = y*Sqrt(r);
  29. }
  30. return r;
  31. }

scfcabsH.cpp : last modifiled at 2016/08/04 10:38:21(783 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:08 (Fri Oct 06 15:27:08 2017).